<?php
/*
 * @Description  : 权限管理
 * @Author       : https://github.com/skyselang
 * @Date         : 2020-05-05
 * @LastEditTime : 2020-12-25
 */

namespace app\store\service\user;

use app\store\model\user\Grade;
use app\store\service\SystemConfig as ServiceSystemConfig;

class AdminPrize
{

    /**
     * 批量配置设置
     * @param 
     */
    public static function save(array $data)
    {
        //系统配置
        $upgrade = $data['upgrade'];
        $systemData = [
            [
                'key'         => 'referee_level',
                'title'       => '直推人会员等级',
                'msg'         => '推荐人会员等级达到需求并且满足推荐人数和自己商品购买次数则享受管理员奖项',
                'value'       => $upgrade['referee_level'],
                'update_time' => date('Y-m-d H:i:s')
            ], [
                'key'         => 'referee_num',
                'title'       => '直推会员数量',
                'msg'         => '推荐人会员等级达到需求并且满足推荐人数和自己商品购买次数则享受管理员奖项',
                'value'       => $upgrade['referee_num'],
                'update_time' => date('Y-m-d H:i:s')
            ], [
                'key'         => 'me_consume_num',
                'title'       => '管理奖者消费次数',
                'msg'         => '推荐人会员等级达到需求并且满足推荐人数和自己商品购买次数则享受管理员奖项',
                'value'       => $upgrade['me_consume_num'],
                'update_time' => date('Y-m-d H:i:s')
            ]
        ];
        ServiceSystemConfig::batchSet($systemData);
        //会员等级利润设置
        foreach ($data['prize'] as $grade_id => $row) {
            $grade_id = str_replace( '_', '',$grade_id);
            Grade::update(['admin_prize' => $row], ['grade_id' => $grade_id]);
        }
    }
}
